<?php

namespace util\file;

class download
{
    static function now($path , $new_filename = NULL, $remove_save_path = true)
    {
        $filename = basename($path);
        header('Content-Description: File Transfer');
        header('Content-Type: '.type::getTypeBySuffix(strstr($filename,'.')));
        header('Content-Disposition: attachment; filename='.$new_filename?:$filename);
        header('Content-Transfer-Encoding: binary');
        header('Expires: 0');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Pragma: public');
        header('Content-Length: ' . filesize($path));
        ob_clean();
        flush();
        readfile($path);
        if($remove_save_path && file_exists($path))
            unlink($path);
        exit();
    }
}